# Contributor: Marian <marian.buschsieweke@ovgu.de>
# Maintainer: Marian <marian.buschsieweke@ovgu.de>
pkgname=micropython
pkgver=1.19.1
pkgrel=0
pkgdesc="lean and efficient Python implementation for MCUs and constrained systems"
url="https://www.micropython.org/"

# ppc64le: mpy-cross fails to compile with "unsupported relocation type 4"
# armhf: fails to build due to "error compiling tools/upip.py"
arch="all !ppc64le !armhf"

license="MIT"
makedepends="libffi-dev python3"
subpackages="$pkgname-cross"
source="micropython-$pkgver.tar.gz::https://github.com/micropython/micropython/archive/v$pkgver.tar.gz
	micropython-1.9.4-prevent-stripping.patch
	no_ussl.patch
	no_legacy_berkeley_db.patch
	"

build() {
	make -C mpy-cross PYTHON=python3
	make -C ports/unix PYTHON=python3
}

check() {
	# float rounding fails https://github.com/micropython/micropython/issues/4176
	case "$CARCH" in
		s390x)
			rm tests/float/float_parse.py tests/float/float_parse_doubleprec.py
			;;
		aarch64)
			rm tests/float/float_parse.py tests/float/float_parse_doubleprec.py
			;;
	esac

	make -C ports/unix test PYTHON=python3
}

package() {
	mkdir -p "$pkgdir/usr/bin"
	install -m755 ports/unix/micropython "$pkgdir/usr/bin/micropython"
}

cross() {
	pkgdesc="Compile micropython code to bytecode, which can be transfered to MCUs"
	cd "$builddir"
	mkdir -p "$subpkgdir/usr/bin"
	install -m755 mpy-cross/mpy-cross "$subpkgdir/usr/bin/mpy-cross"
}

sha512sums="
481159d1198777857ee530bf9dd6dd2dbd8990dcf764f7cdb2f01f1b7a960bea4b7887b47b8dc0ca5eca445334a1ac67ae0afed481ffc1b1e08802c106b751a9  micropython-1.19.1.tar.gz
eff33f41757048113d013cb30566c5d1eed72fdbd3cd7b046655efb168f39165e3bb17fa3c29a8f27039393db9363a8a12b9d75faa21fc6c370b16500a54ef52  micropython-1.9.4-prevent-stripping.patch
9a6cd131c8875a9d320653b7b93d46a759eee3255e25763eb8de6934b3035f691e497eafc9412320f13c5921a384d42d6e60ea3eb3d65f3a6101dae9be514f3c  no_ussl.patch
e86ad02ef746605f2f685ae776a6ad6ea39ae6e57fa0869a0c03895fd581647de20fa7e6aaeebac45e7302a63451d625208b1356ee2f35a66df70ac2755a25ff  no_legacy_berkeley_db.patch
"
